package com.study.design.pattern.pattern.behavioral.observer.guava;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import java.util.concurrent.Executors;

/**
 * @Author: gongsl
 * @Date: 2025-03-24 20:53
 */
public class AsyncTest {
    private static final EventBus asyncEventBus = new AsyncEventBus(Executors.newFixedThreadPool(4));

    public static void main(String[] args) {
        asyncEventBus.register(new DeadEventListener());
        // 模拟快递状态更新
        updateDeliveryStatus("ORDER_123", "已发货", "13800138000");
        System.out.println("======end======");
    }

    /**
     * 业务方法：更新快递状态并发布事件
     */
    private static void updateDeliveryStatus(String orderId, String newStatus, String phone) {
        System.out.println("====== 更新物流状态至：" + newStatus + " ======");
        // 创建并发布事件
        DeliveryStatusUpdateEvent event = new DeliveryStatusUpdateEvent(orderId, newStatus, phone);
        // 触发所有订阅者的处理方法
        asyncEventBus.post(event);
    }
}
